﻿@{
    Page.Title = "";
    Layout = "~/_SiteLayout.cshtml";
    string appid = Request.QueryString["appid"];
    string tabid = Request.QueryString["tabid"];
    string typeid = Request.QueryString["typeid"];
    string title = string.Empty;
    string address = string.Empty;

    Business.Platform.Dictionary bdict = new Business.Platform.Dictionary();
    Business.Platform.AppLibrary bapp = new Business.Platform.AppLibrary();
    if(IsPost)
    {
        title = Request.Form["Title"];
        address = Request.Form["Address"];

        if (!Request.Form["DeleteBut"].IsNullOrEmpty())
        {
            Business.Platform.AppLibrary bappLibrary = new Business.Platform.AppLibrary();
            string deleteID = Request.Form["checkbox_app"];
            System.Text.StringBuilder delxml = new System.Text.StringBuilder();
            foreach(string id in deleteID.Split(','))
            {
                Guid gid;
                if(id.IsGuid(out gid))
                {
                    delxml.Append(bappLibrary.Get(gid).Serialize());
                    bappLibrary.Delete(gid);
                }
            }
            Business.Platform.Log.Add("删除了一批应用程序库", delxml.ToString(), Business.Platform.Log.Types.角色应用);
        }
    }
    else
    {
        title = Request.QueryString["Title"];
        address = Request.QueryString["Address"];
    }
    
    string query = string.Format("&appid={0}&tabid={1}&Title={2}&typeid={3}&Address={4}",
                Request.QueryString["appid"],
                Request.QueryString["tabid"],
                title.UrlEncode(), typeid, address.UrlEncode()
                );
    string query1 = string.Format("{0}&pagesize={1}&pagenumber={2}", query, Request.QueryString["pagesize"], Request.QueryString["pagenumber"]);
    string pager;
    string typeidstring = typeid.IsGuid() ? bapp.GetAllChildsIDString(typeid.ToGuid()) : "";
    List<Data.Model.AppLibrary> appList = bapp.GetPagerData(out pager, query, title, typeidstring, address);
    
}

<form action="" method="post" >
<div class="querybar">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                应用名称：<input type="text" class="mytext" id="Title" name="Title" value="@title" style="width:180px" />
                应用地址：<input type="text" class="mytext" id="Address" name="Address" value="@address" style="width:280px" />
                <input type="submit" name="Search" value="查询" class="mybutton" />
            </td>
        </tr>
    </table>
</div>
<div class="toolbar" style="margin-top:0; border-top:0;">
    <a href="javascript:void(0);" onclick="add();return false;"><span style="background-image:url(/Images/ico/folder_classic_stuffed_add.png);">添加应用</span></a>
    <span class="toolbarsplit">&nbsp;</span>
    <input type="submit" style="display:none;" value="d" id="DeleteBut" name="DeleteBut" />
    <a href="javascript:void(0);" onclick="del();return false;"><span style="background-image:url(/Images/ico/folder_classic_stuffed_remove.png);">删除所选</span></a>
</div>
<table cellpadding="0" cellspacing="1" border="0" class="listtable">
    <thead>
        <tr>
            <th><input type="checkbox" onclick="checkAll(this.checked);" style="vertical-align:middle;" />应用名称</th>
            <th>应用地址</th>
            <th>应用分类</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    @{
    foreach (var app in appList)
    {
        <tr>
            <td><input type="checkbox" value="@app.ID" name="checkbox_app" />@app.Title</td>
            <td>@app.Address</td>
            <td>@bdict.GetTitle(app.Type)</td>
            <td><a class="editlink" href="javascript:void(0);" onclick="edit('@app.ID');return false;">编辑</a></td>
        </tr>
    }    
    }
    </tbody>
</table>
<div class="buttondiv">@Html.Raw(pager)</div>
</form>

<script type="text/javascript">
    var appid = '@appid';
    var iframeid = '@tabid';
    var typeid = '@typeid';
    var dialog = top.mainDialog;
    function add()
    {
        dialog.open({ id: "window_" + appid.replaceAll('-', ''), title: "添加应用程序", width: 700, height: 350, url: '/Platform/AppLibrary/Edit?1=1' + '@query1', openerid: iframeid });
    }
    function edit(id)
    {
        dialog.open({ id: "window_" + appid.replaceAll('-', ''), title: "编辑应用程序", width: 700, height: 350, url: '/Platform/AppLibrary/Edit?id=' + id + '@query1', openerid: iframeid });
    }
    function checkAll(checked)
    {
        $("input[name='checkbox_app']").prop("checked", checked);
    }
    function del()
    {
        if ($(":checked[name='checkbox_app']").size() == 0)
        {
            alert("您没有选择要删除的项!");
            return false;
        }
        if (!confirm('您真的要删除所选应用吗?'))
        {
            return false;
        }
        $("#DeleteBut").click();
        return true;
    }
</script>